package com.project.dao.imp;

import com.project.bean.CountryBean;
import com.project.dao.ICountryDao;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Repository
public class CountryDaoImp extends BaseDao implements ICountryDao {
    @Override
    public List<CountryBean> findAll() {

            List<CountryBean> list = new ArrayList<>();
            this.setConnection();
            try {
                ps = con.prepareStatement("select * from t_country");
                rs = ps.executeQuery();
                while(rs.next()){
                    CountryBean CountryBean = new CountryBean();
                    CountryBean.setId(rs.getInt("pk_countryId"));
                    CountryBean.setName(rs.getString("c_name"));
                    list.add(CountryBean);
                }

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally{
                this.closeConnection();
            }

            return list;
        }
    }

